package io.spring.sample.graphql.repository;

import com.querydsl.core.types.dsl.StringPath;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer;
import org.springframework.data.querydsl.binding.QuerydslBindings;
import org.springframework.data.repository.CrudRepository;
import org.springframework.graphql.data.GraphQlRepository;


@GraphQlRepository
public interface Books extends
		JpaRepository<Book, String>, QuerydslPredicateExecutor<Book>{

}


/*
自定义过滤比较模式： 默认是 .eq. 过滤: book.a=Book.a;
, QuerydslBinderCustomizer<QBook> {

	@Override
	default void customize(QuerydslBindings bindings, QBook book) {
		bindings.bind(book.book.id).first((path, value) -> path.isNull().or(path.startsWithIgnoreCase(value))) ;
		bindings.bind(book.book.name).first((path, value) -> path.isNull().or(path.startsWithIgnoreCase(value))) ;
		bindings.bind(String.class).first(
				(StringPath path, String value) -> path.isNull().or(path.containsIgnoreCase(value)));
	}

}

* */